module project.directory;

import project.file;
import project.project;

class Directory {
    private string myName;
    private const Project myProject;
    private Directory[] myChildrenDirectories;
    private Directory myParentDirectory;
    private File[] myChildrenFiles;

    public this(in Project project, Directory parentDirectory = null, in string name = "")
    in {
        assert(project !is null);
    }
    body {
        myName = name;
        myProject = project;
        myParentDirectory = parentDirectory;
        myChildrenDirectories = new Directory[0];
        myChildrenFiles = new File[0];
    }

    public bool isEmpty() const {
        return
            (myChildrenDirectories.length == 0)
            && (myChildrenFiles.length == 0);
    }

    public void setName(in string name) {
        myName = name;
    }

    public string getName() {
        return myName;
    }

    public void addPackage(Directory dir) {
        myChildrenDirectories ~= dir;
    }

    public Directory[] getChildrenDirectories() {
        return myChildrenDirectories;
    }

    public void addFile(File file) {
        myChildrenFiles ~= file;
    }

    public string getPath() {
        if (myParentDirectory is null) {
            return myProject.getPath();
        }
        return myParentDirectory.getPath() ~ myName;
    }

    public File[] getChildrenFiles() {
        return myChildrenFiles;
    }
}
